﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using AbbrWordWikiDB;

namespace AbbrWordWiki
{
    public partial class DetailsPage : PhoneApplicationPage
    {
        private string _fullWord;
        // Constructor
        public DetailsPage()
        {
            InitializeComponent();
        }

        // When page is navigated to set data context to selected item in list
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.TryGetValue("selectedWord", out _fullWord))
            {
                foreach (t_AbbrWordWiki abbrWord in App.ViewModel.AbbrWordsViewData)
                {
                    if (abbrWord.FullWord.ToLower().StartsWith(_fullWord.ToLower()))
                    {
                        this.CaptextBlock.Text = abbrWord.Word.Substring(0, 1);
                        this.RestTextBlock.Text = abbrWord.Word.Substring(1);
                        this.FullWordTextBlock.Text = abbrWord.FullWord.Substring(1);
                        this.DescriptionTextBlock.Text = abbrWord.Description;
                    }
                }
            }
        }

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Navigate to the new page
            NavigationService.Navigate(new Uri("/EditWordPage.xaml?fullWord=" + _fullWord, UriKind.Relative));
        }

        private void Image_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }
    }
}